import { defineConfig,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { viteMockServe } from 'vite-plugin-mock'
import path from 'path'
// https://vitejs.dev/config/

//引入svg需要用到的插件
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
export default defineConfig(({ command,mode }) => {
  let env = loadEnv(mode,process.cwd())
  return {
    plugins: [vue(), createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
      symbolId: 'icon-[dir]-[name]',
    }), viteMockServe({
      localEnabled: command === 'serve',
    })],
    resolve: {
      alias: {
        "@": path.resolve("./src")
      }
    },
    css:{
      preprocessorOptions:{
        scss:{
          javascriptEnabled:true,
          additionalData:'@import "./src/styles/variable.scss";',
        }
      }
    },
    serve:{
      proxy:{
          '/api':{
             target:'http://sph-api.atguigu.cn',
             changeOrigin:true,
             rewrite:(path) =>path.replace(/^\/api/,'')
          }
      }
    }
  }
})
